import { request } from "./index";

import "nprogress/nprogress.css";
import nProgress from "nprogress";
import store from '@/store'
request.interceptors.request.use((config) => {
	// 发送请求开启进度条
	nProgress.start();

	config.headers.userTempId=store.state.user.userTempId

	const token=store.state.user.token
	config.headers.token=token
	return config;
});
request.interceptors.response.use(
	(response) => {
		console.log(response, "response");
		// 响应结束就关闭进度条
		nProgress.done();
		if (response.data.code === 200) {
			return response.data.data;
		} else {
			return Promise.reject({
				message: response.data.message,
			});
		}
	},
	(error) => {
		// 响应结束就关闭进度条
		nProgress.done();
		return Promise.reject(error);
	}
);
export default request;
